package com.njust.bean;

import com.njust.dao.BookDao;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class IOCTest6 {

    private ConfigurableApplicationContext ioc;

    @Before
    public void tearUp(){
        ioc = new ClassPathXmlApplicationContext("config/ioc6.xml");
    }

    /**
     * 实验15：通过注解分别创建Dao、Service、Controller★
     *
     * Caused by: java.lang.ClassNotFoundException:
     * org.springframework.aop.TargetSource
     *
     * 使用注解加入到容器中的组件，和使用配置加入到容器中的组件行为都是一样的
     * 1、组件的id都是类名首字母小写
     * 2、组件的作用域：默认都是单例的
     */
    @Test
    public void test15(){

        BookDao bookDao = ioc.getBean("bookDao", BookDao.class);
        System.out.println("bookDao = " + bookDao);
        BookDao bookDao2 = ioc.getBean("bookDao", BookDao.class);
        System.out.println(bookDao == bookDao2);
//        BookDao bookDao3 = ioc.getBean("bookdaohaha", BookDao.class);
//        System.out.println(bookDao3);

    }
}
